package org.eweb4j.mvc.config.creator;

import org.eweb4j.mvc.config.bean.FieldConfigBean;
import org.eweb4j.mvc.config.bean.ValidatorConfigBean;
import org.eweb4j.mvc.validator.ValidatorConstant;
import org.eweb4j.mvc.validator.annotation.RequiredVal;


public class RequiredImpl implements ValidatorCreator {

	private RequiredVal ann;

	public RequiredImpl(RequiredVal ann) {
		this.ann = ann;
	}

	public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
		if (this.ann == null)
			return null;
		if (val == null || !ValidatorConstant.REQUIRED_VAL.equals(val.getName())) {
			val = new ValidatorConfigBean();
			val.setName(ValidatorConstant.REQUIRED_VAL);
		}

		FieldConfigBean fcb = new FieldConfigBean();
		fcb.setName(fieldName);
		fcb.setMessage(ann.mess());

		val.getField().add(fcb);

		return val;
	}

}
